﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Ccit.Utils;
using Ccit.OA.MsNotify;
using System.Text;
namespace Ccit.OA.Notify
{
    public class NotifyBLL
    {
        private INotify iNotify = null;
        public NotifyBLL()
        {
            iNotify = (INotify)Factory.CreateObject("Ccit.OA.Notify.dll", "Ccit.OA.Notify.Notify",
                                                ImportComponentType.DotNetDll, null);
        }
         /// <summary>
        /// 获取菜单树信息
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        public string GetNotiFyNodes(string Query)
        {
            string sXML = iNotify.GetNotiFyNodes(Query);
            iNotify = null;
            return sXML;
        }
        /// <summary>
        /// 保存通知类型
        /// </summary>
        /// <param name="ms"></param>
        /// <returns></returns>
        public List<string> DoSaveNotiFy(MsNotifyClass ms)
        {
            List<string> lstResult = iNotify.DoSaveNotiFy(ms);
            iNotify = null;
            return lstResult;
        }
        /// <summary>
        /// 删除信息
        /// </summary>
        /// <param name="sId"></param>
        /// <returns></returns>
        public List<string> DoOperateNotiFy(string sId)
        {
            List<string> lstResult = iNotify.DoOperateNotiFy(sId);
            iNotify = null;
            return lstResult;
        }
         /// <summary>
        /// 获取类型信息
        /// </summary>
        /// <param name="sId"></param>
        /// <returns></returns>
        public MsNotifyClass GetNotiFyMes(string sId)
        {
            MsNotifyClass Ms = iNotify.GetNotiFyMes(sId);
            iNotify = null;
            return Ms;
        }
        /// <summary>
        /// 获取通知发布列表信息
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        public List<MsNotifyMessage> GetNotifyMessage(string Query,string type)
        {
            if (type == "2")
            {
                Query = GetQueryXMl(Query, "1");
            }
            List<MsNotifyMessage> lstNotify = iNotify.GetNotifyMessage(Query);
            iNotify = null;
            return lstNotify;
        }
        /// <summary>
        /// 删除通知信息和浏览信息
        /// </summary>
        /// <param name="NotifyId">主键ID</param>
        /// <param name="type">判断类型1:删除，0:修改</param>
        /// <param name="state">修改参数</param>
        /// <returns></returns>
        public List<string> DoOperateNotify(string NotifyId, string type, string state)
        {
            List<string> lstResult = iNotify.DoOperateNotify(NotifyId, type, state);
            iNotify = null;
            return lstResult;
        } /// <summary>
        /// 添加通知类型
        /// </summary>
        /// <param name="ddlList"></param>
        public void DoAddDownList(ref DropDownList ddlList)
        {
            iNotify.DoAddDownList(ref ddlList);
            iNotify = null;
        }
        /// <summary>
        /// 保存NTF_A2(通知信息表)
        /// </summary>
        /// <param name="ms"></param>
        /// <returns></returns>
        public List<string> DoSaveNotiFyMessage(MsNotifyMessage ms)
        {
            List<string> lstResult = iNotify.DoSaveNotiFyMessage(ms);
            iNotify = null;
            return lstResult;
        }
        /// <summary>
        /// 获取通知内容信息
        /// </summary>
        /// <param name="NotifyId"></param>
        /// <returns></returns>
        public string GetNotyfyContent(string NotifyId)
        {
            string content = iNotify.GetNotyfyContent(NotifyId);
            iNotify = null;
            return content;
        }
        /// <summary>
        /// 获取通知类型编剧页面信息
        /// </summary>
        /// <param name="NotifyId"></param>
        /// <returns></returns>
        public MsNotifyMessage GetNotiFyMessage(string NotifyId)
        {
            MsNotifyMessage ms = iNotify.GetNotiFyMessage(NotifyId);
            iNotify = null;
            return ms;
        }
         /// <summary>
        ///  获取回复列表页面
        /// </summary>
        /// <param name="NotifyId"></param>
        /// <returns></returns>
        public List<MsNotifyMessage> GetReplyViewMes(string NotifyId,string Query)
        {
            List<MsNotifyMessage> lstMs = iNotify.GetReplyViewMes(NotifyId,Query);
            iNotify = null;
            return lstMs;
        }
         /// <summary>
        /// 获取条件设置信息
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public DataSet GetQueryMessage(string typeId)
        {
            DataSet dSet = iNotify.GetQueryMessage(typeId);
            iNotify = null;
            return dSet;
        }
        /// <summary>
        /// 删除条件信息
        /// </summary>
        /// <param name="queryId"></param>
        /// <returns></returns>
        public string DoOperateQuery(string queryId)
        {
            string iNum = iNotify.DoOperateQuery(queryId);
            iNotify = null;
            return iNum;
        }
        /// <summary>
        /// 保存条件信息
        /// </summary>
        /// <param name="ms"></param>
        /// <returns></returns>
        public List<string> DoSaveQuery(MsQueryClass ms)
        {
            List<string> lstResult = iNotify.DoSaveQuery(ms);
            iNotify = null;
            return lstResult;
        }
        /// <summary>
        /// 获取条件信息
        /// </summary>
        /// <param name="QueryId"></param>
        /// <returns></returns>
        public MsQueryClass GetQueryEdit(string QueryId)
        {
            MsQueryClass ms = iNotify.GetQueryEdit(QueryId);
            iNotify = null;
            return ms;
        }
         /// <summary>
        /// 获取类型信息
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        public DataSet GetDictLibMes()
        {
            DataSet dSet = iNotify.GetDictLibMes();
            iNotify = null;
            return dSet;
        } 
        /// <summary>
        ///  获取通知浏览页面
        /// </summary>
        /// <param name="NotifyId"></param>
        /// <returns></returns>
        public List<MsNotifyMessage> GetViewMes(string Query,string type)
        {
            if (type == "2")
            {
                Query = GetQueryXMl(Query, "2");
            }
            List<MsNotifyMessage> lstMs = iNotify.GetViewMes(Query);
            iNotify = null;
            return lstMs;
        }
        private string GetQueryXMl(string Query,string type)
        {
            if (Query != "")
            {
                string[] content = Query.Split('~');
                string TitleName = (content[0].ToString() != "") ? content[0].ToString() : "";
                string Content = (content[1].ToString() != "") ? content[1].ToString() : "";
                string Creator = (content[2].ToString() != "") ? content[2].ToString() : "";

                string Level = (content[3].ToString() != "") ? content[3].ToString() : "";
                string PubFlag = (content[4].ToString() != "") ? content[4].ToString() : "";
                string Class = (content[5].ToString() != "") ? content[5].ToString() : "";
                string typeCount = (content[6].ToString() != "") ? content[6].ToString() : "";
                string dayTime = "";

                if (typeCount == "4")
                {

                    dayTime = (content[7].ToString() != "") ? content[7].ToString() : "";
                }
                if (typeCount == "5")
                {

                    string begInTime = (content[7].ToString() != "") ? content[7].ToString() : "";
                    string endTime = (content[8].ToString() != "") ? content[8].ToString() : "";
                    dayTime = begInTime + "~" + endTime;
                }
                StringBuilder sbXML = new StringBuilder();
                sbXML.Append("<Query><TitleName><![CDATA[").Append(TitleName).Append("]]></TitleName>");
                sbXML.Append("<Content><![CDATA[").Append(Content).Append("]]></Content>");
                sbXML.Append("<Creator><![CDATA[").Append(Creator).Append("]]></Creator>");
                sbXML.Append("<Level><![CDATA[").Append(Level).Append("]]></Level>");
                if (type == "1")
                {
                    sbXML.Append("<PubFlag><![CDATA[").Append(PubFlag).Append("]]></PubFlag>");
                    sbXML.Append("<ReadFlag><![CDATA[").Append("").Append("]]></ReadFlag>");
                }
                else
                {
                    sbXML.Append("<PubFlag><![CDATA[").Append("").Append("]]></PubFlag>");
                    sbXML.Append("<ReadFlag><![CDATA[").Append(PubFlag).Append("]]></ReadFlag>");
                }
                sbXML.Append("<Class><![CDATA[").Append(Class).Append("]]></Class>");
                sbXML.Append("<Time Type='" + typeCount + "'><![CDATA[").Append(dayTime).Append("]]></Time>");
                sbXML.Append("</Query>");
                Query = sbXML.ToString();
            }
            return Query;
        }
         /// <summary>
        /// 获取打印页面通知信息
        /// </summary>
        /// <param name="NotifyId"></param>
        /// <returns></returns>
        public MsNotifyMessage GetReplyView(string NotifyId)
        {
            MsNotifyMessage ms = iNotify.GetReplyView(NotifyId);
            //iNotify = null;
            return ms;
        }
        /// <summary>
        /// 获取浏览信息内容
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="NotifyId"></param>
        /// <returns></returns>
        public string GetUserMessage(string userId, string NotifyId)
        {
            string viewMes = iNotify.GetUserMessage(userId, NotifyId);
            //iNotify = null;
            return viewMes;
        }
         /// <summary>
        /// 操作浏览信息表
        /// </summary>
        /// <param name="ms"></param>
        /// <returns></returns>
        public string DoOperateReplyView(MsViewClass ms)
        {
            string iNum = iNotify.DoOperateReplyView(ms);
            iNotify = null;
            return iNum;
        }
    }
}
